package com.shu.logsearch.jsch.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.shu.logsearch.common.annotation.BaseViewDirectory;
import com.shu.logsearch.common.base.BaseController;
import com.shu.logsearch.common.web.Result;
import com.shu.logsearch.jsch.dto.RemoteServerConfigDto;
import com.shu.logsearch.jsch.model.RemoteServerConfig;
import com.shu.logsearch.jsch.service.RemoteServerConfigService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Tree Cai
 * @date 2019/7/10
 */

@Controller
@RequestMapping("/remoteServerConfig")
@BaseViewDirectory("remoteServerConfig")
public class RemoteServerConfigController extends BaseController<RemoteServerConfig, RemoteServerConfigService> {

    @RequestMapping("/save")
    @ResponseBody
    public Result save(RemoteServerConfig remoteServerConfig) {
        if (remoteServerConfig.checkProperties())
            return Result.ERROR("请检查必填项！！！");
        if (StringUtils.isEmpty(remoteServerConfig.getId()))
            return Result.DEFAULT_RESULT(service.save(remoteServerConfig));
        return Result.DEFAULT_RESULT(service.updateById(remoteServerConfig));
    }

    @RequestMapping("/list")
    @ResponseBody
    public Result list(RemoteServerConfigDto remoteServerConfigDto) {
        if (StringUtils.isEmpty(remoteServerConfigDto.getUserId()))
            return Result.EMPTY_PAGE();
        Page pages = PageHelper.startPage(remoteServerConfigDto.getPageNum(), remoteServerConfigDto.getPageSize());
        QueryWrapper<RemoteServerConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId",remoteServerConfigDto.getUserId());
        service.list(queryWrapper);
        return Result.PAGE(null);
    }


}
